function ReTry
{
  param( [string] $Description = ${throw "Description is required for ReTry"}
       , [ScriptBlock] $Command  = ${throw "Command is required for ReTry"}
       , [switch] $NoRetry
       , [switch] $AllowSkip
       , [switch] $ShowStatus
       )

  $breakStr = "--------------------------------------------------------------------"  
  # must use script level variable because trap occurs in new scope
  # executingCommand is used to control Continue from Trap
  # It gets set to $false by success or by Continue Option.
  $script:executingCommand = $true
  while ( $script:executingCommand )
  {
    # must use script level variable because trap occurs in new scope
    # Is used to control Ending Status of OK
    $script:errorOccured = $false
    
    # Show Status while executing step
    if ( $ShowStatus )
    {
      Log-Message "$($Description): " -noNewLine
    }
    
    ########################################################################################
    # Main logic of this function is to Trap and manage the $command
    trap
    {
      $script:errorOccured = $true
      
      # Process failed... Show Status
      if ( $ShowStatus )
      {
        Log-Message "[FAILED]" -foregroundcolor red  -backgroundcolor black
      }
      
      Log-Message $breakStr
      # Get the Error Object
      $err = $error[0]
      $errMsg = $err.Exception.Message

      # If the Error message contains the following, remove it.
      $noiseString = 'Command execution stopped because the shell variable "ErrorActionPreference" is set to Stop: '
      if ($errMsg.StartsWith($noiseString))
      {
        $errMsg = $errMsg.Remove(0, $noiseString.Length)
      }

      # This may be ugly... but the intent is for it to stand out yet be readable.
      Log-Message "Error while performing action:" -noNewLine -foregroundcolor black -backgroundcolor white
      Log-Message " $Description" -foregroundcolor Yellow -backgroundcolor black
#      Log-Message "                   Error Line:" -noNewLine -foregroundcolor black -backgroundcolor white
#      Log-Message " $($err.InvocationInfo.Line)" -foregroundcolor Yellow -backgroundcolor black
      Log-Message "                Error Message:" -noNewLine -foregroundcolor black -backgroundcolor white
      Log-Message "$errMsg" -foregroundcolor Yellow -backgroundcolor black
      if ($NoPrompt)
      {
        throw $error[0].Exception
      }
      
      # build prompt.  Stop and Exit are always options
      $prompt = "[A] Abort Process - [X] Exit Command"
      
      if ($AllowSkip)
      {
        $prompt += " - [S] Skip"
      }
      
      if (!$NoRetry)
      {
        $prompt += " - [R] Retry"
      }
      
      $prompt += " - [?] Help"
      
      $askQuestion = $true
      while ($askQuestion)
      {
        Log-Message $breakStr
        $answer = Read-Host $prompt
        switch ($answer)
        { "A"   { 
                  Log-Message "ABORTING"   -foregroundcolor black -backgroundcolor white
                  throw $error[0].exception 
                }
          "X"   { 
                  Log-Message "EXIT"   -foregroundcolor black -backgroundcolor white
                  exit 
                }
          "S"   { 
                  if ($AllowSkip)
                  {
                    $script:executingCommand = $false
                    Log-Message "SKIP -"  -nonewline -foregroundcolor black -backgroundcolor white
                    Log-Message " $Description" -foregroundcolor Yellow -backgroundcolor black
                    $askQuestion = $false
                  }
                }
          "R"   { 
                  if (!$NoRetry)
                  {
                    $script:executingCommand = $true
                    Log-Message "RETRY -"  -nonewline -foregroundcolor black -backgroundcolor white
                    Log-Message " $Description" -foregroundcolor Yellow -backgroundcolor black
                    $askQuestion = $false
                  }
                }
           
        }
        if ($askQuestion)
        { 
          if( $answer -ne "?" -and $answer -ne "" )
          {
            Log-Message "Option '$answer' is not supportd.  Please choose one of the following:"  -foregroundcolor Yellow -backgroundcolor black
          }
          Log-Message $breakStr
          Log-Message "[A] - Stops this step in the current process."
          Log-Message "      This may result in termination or a retry of "
          Log-Message "      the current process from the beginning"
          Log-Message "[X] - Exits Command completly."
          if ($AllowSkip)
          {
            Log-Message "[S] - Skips current step in process"
            Log-Message "      Subsequent errors might occur because of this failed step"
          }
          if (!$NoRetry)
          {
            Log-Message "[R] - Retrys the current step in the process"
          }
        }
      }
      Log-Message $breakStr
      Continue;
    }
  
    &$Command
    
    if (!$script:errorOccured)
    {
      $script:executingCommand = $false
      if ( $ShowStatus )
      {
        Log-Message "[OK]" -foregroundcolor green  -backgroundcolor black
      }
    }
  }
}
